package com.dhz.common.base.utils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author FY
 */
public class LRUMap<K, V> extends LinkedHashMap<K, V> {

    /** LRU max size */
    private int maxSize;

    public LRUMap() {
        this(Integer.MAX_VALUE);
    }

    public LRUMap(int maxSize) {
        super(maxSize + 1, 1f, true);
        this.maxSize = maxSize;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return size() > maxSize;
    }
}
